feat(capture): add capture_mode config scaffolding (capture v1, 1/6)#701
Draft
eli-r-ph wants to merge 2 commits into
Draft
feat(capture): add capture_mode config scaffolding (capture v1, 1/6)#701eli-r-ph wants to merge 2 commits into
eli-r-ph wants to merge 2 commits into
Conversation
Contributor
|
Reviews (1): Last reviewed commit: "feat(capture): add capture_mode config s..." | Re-trigger Greptile |
Contributor
posthog-python Compliance ReportDate: 2026-06-28 00:30:02 UTC ✅ All Tests Passed!45/45 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 16/16 tests passed View Details
|
This was referenced Jun 27, 2026
531fb62 to
33ebdfb
Compare
33ebdfb to
b508cf9
Compare
Introduce a CaptureMode enum (V0 legacy /batch/, V1 /i/v1/analytics/events) and resolve_capture_mode() with precedence kwarg > POSTHOG_CAPTURE_MODE env > V0. Plumb capture_mode through Client and Consumer (including fork-reinit and the module-level default client). The mode is resolved and stored but inert in this change: V0 still runs everywhere, so behavior is unchanged. First of a stacked series adding Capture V1 support.
Set the env to the opposite mode in each precedence row so every case actually exercises kwarg-over-env, and assert an invalid kwarg raises even when a valid env value is present.
b508cf9 to
b139d02
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
First PR in a stacked series adding Capture V1 (
POST /i/v1/analytics/events) support to the SDK, at parity with posthog-go'sCaptureModeand posthog-rs'scapture-v1.This PR is pure, inert scaffolding: it adds the capture-mode selector and threads it everywhere it will be needed, but changes no runtime behavior — V0 (legacy
/batch/) still runs on every path. Later PRs add the v1 serializer, transport, wiring, harness suite, and docs.CaptureModeenum:V0(legacy/batch/, the default) andV1(/i/v1/analytics/events).resolve_capture_mode()with precedence explicit kwarg >POSTHOG_CAPTURE_MODEenv >V0. Env acceptsv0/legacyandv1/analytics_v1(mirrors posthog-go's vocabulary); an unrecognized env value warns and defaults toV0so a typo never silently flips the wire protocol. An invalid explicit kwarg raisesValueError(explicit misconfig should be loud).Client.__init__(resolved + stored asself.capture_mode), bothConsumer(...)constructions (initial + fork-reinit), and the module-level default client.Consumerstores it but does not yet act on it.💚 How did you test it?
posthog/test/test_capture_mode.py(25 cases): resolution precedence, env aliases/case/whitespace, blank-env default, unrecognized-env warn+default, invalid-kwarg raises, and plumbing toClient.capture_mode+ per-Consumerpropagation (incl. multi-thread).test_consumer,test_client,test_module,test_client_fork,test_dedicated_ai_endpoint+ the new file — 213 passed.ruff format/ruff checkclean;mypyclean on new modules; regeneratedreferences/public_api_snapshot.txt.📝 Checklist
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Authored with Cursor (Claude Opus 4.8) following a pre-agreed, hardened implementation plan. Design decisions: enum members are Pythonic
V0/V1(not posthog-go'sLegacy/AnalyticsV1) but the env var accepts both spellings for cross-SDK consistency; the env typo path defaults defensively while an explicit bad kwarg fails fast. Mode is fully inert here by design to keep this PR a no-op for existing users and easy to review. Changeset (sampo add) and docs are intentionally deferred to the final PR so the feature releases as one entry.